package com.study.compose.beta.view

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.module.compose.base.composable.CodeView

@Composable
fun StateSample() {
    //关键字by可把MutableState自动拆包为value,也可使用=好进行复制，但是返回的是MutableState
    var name by remember { mutableStateOf("hello compose") }

    LazyColumn(
        Modifier
            .fillMaxSize()
            .padding(start = 15.dp, end = 15.dp)
    ) {
        item {
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .fillMaxHeight(),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(modifier = Modifier.padding(20.dp), text = name)
                Button(onClick = { name = "Zhang" }) {
                    Text(text = "你点我啊")
                }

                CodeView(
                    code =
                    """
                    //关键字by可把MutableState自动拆包为value,也可使用=好进行赋值，但是返回的是MutableState
                    //注意：导包import androidx.compose.runtime.*
                    //val name = remember { mutableStateOf("hello compose") }
                    var name by remember { mutableStateOf("hello compose") }
    
                    Text(modifier = Modifier.padding(20.dp), text = name)
                    Button(onClick = { name = "Zhang" }) {
                        Text(text = "你点我啊")
                    }
                    """.trimIndent()
                )
            }
        }

    }
}